﻿
<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>计划占用</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/js/layui/css/layui.css" rel="stylesheet" />
    <link href="~/X-admin/css/font.css" rel="stylesheet" />
    @* <script src="~/js/layui/layui.js"></script> *@
    <script src="~/X-admin/lib/layui/layui.js"></script>
    <link href="~/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/X-admin/js/jquery.min.js"></script>
    <script src="~/X-admin/js/xadmin.js"></script>
    <script src="~/js/framework/sysframework.js"></script>
    <script src="~/js/sysweb/planjs.js"></script>
</head>
<body>
    <ul lay-bar="disabled" class="mWebBanner">
      @*   <li class="layui-nav-item" style="float:left;">
            <button type="button" name="btn_update" onclick="applyPurchase()" class="buttonCss">
                <i class="layui-icon" style="margin-right:3px">&#xe698;</i>申请采购
            </button>
        </li> *@
        <li class="layui-nav-item" style="float:left;">
            <button type="button" onclick="seleCtProduct()" class="buttonCss">
                <i class="layui-icon" style="margin-right:3px">&#xe63c;</i>选择原辅料
            </button>
        </li>
        <li class="layui-nav-item" style="float:left;margin-left:3%">
            <button  type="button" onclick="closeWin()" class="buttonCss">
                <i class="layui-icon" style="margin-right:3px">&#x1007;</i>关闭页面
            </button>
        </li>
    </ul>
    <div class="layui-card" style="margin-top:1%;padding-top:2%" >
        <form id="qForm" name="qForm">
            <div class="layui-form-item">
                <div class="layui-input-group" style="float:left;">
                    <div class="layui-input-prefix">
                        生产计划号
                    </div>
                    <input type="text" id="plCode" name="plCode" class="layui-input" style="width:120%" readonly />
                </div>
                <div class="layui-input-group" style="float:left;margin-left:70px">
                    <div class="layui-input-prefix">
                        客户名称
                    </div>
                    <input type="text" id="cuName" name="cuName" class="layui-input" style="width:120%" readonly />
                </div>
                <div class="layui-input-group" style="float:left;margin-left:70px">
                    <div class="layui-input-prefix">
                        存货名称
                    </div>
                    <input type="text" id="proName" name="proName" class="layui-input" style="width:120%" readonly/>
                </div>

            </div>
            <div class="layui-form-item">
               
           

                <div class="layui-input-group" style="float:left;margin-left:2%">
                    <div class="layui-input-prefix">
                        规 格
                    </div>
                    <input type="text" id="spec" name="spec" class="layui-input" style="width:120%" readonly />
                </div>

                <div class="layui-input-group" style="float:left;margin-left:70px">
                    <div class="layui-input-prefix">
                        生产数量
                    </div>
                    <input type="text" id="planNum" name="planNum" class="layui-input"  readonly />
                </div>
            </div>

            <input type="hidden" id="proCode" name="proCode">
     
            <input type="hidden" id="numType" name="numType">
        </form>
        
        <div class="layui-card-body layui-table-body layui-table-main" >
            <table class="layui-hide" id="list" lay-filter="list"></table>
        </div>
        <div class="layui-card-body layui-table-body" id="layui-table-main"  style="margin-top:1%">
            <table class="layui-hide" id="zylist" lay-filter="zylist"></table>
        </div>
    </div>

</body>
</html>
<script type="text/html" id="barDemo">
    <a title="明细数据" href="javascript:;" lay-event="view"><i class="layui-icon">&#xe615;</i></a>
</script>
<script type="text/html" id="zyTools">
    <a title="删除信息" href="javascript:;" lay-event="del" ><i class="layui-icon">&#xe640;</i></a>
</script>
<script>
    // var webCode = "";
    var proCode = "0";
    var plCode = "", planNum = "", proName = "", spec = "", cuName="";

    $(function () {
        proCode = getUrlVariable("proCode");
        plCode = getUrlVariable("plCode");
        planNum = getUrlVariable("planNum");
        proName = getUrlVariable("proName");
        spec = getUrlVariable("spec");
        cuName = getUrlVariable("cuName");
        $("input[ name='plCode']").val(plCode);
        $("input[ name='planNum']").val(planNum);
        $("input[ name='proCode']").val(proCode);
        $("input[ name='numType']").val("bar");
        $("input[ name='proName']").val(proName);
        $("input[ name='spec']").val(spec);
        $("input[ name='cuName']").val(cuName);
        loadBOM();
        ZhYList();
    })

    var dUrl = "../Plan/getDataList?dataType=pml&condition=";
    var zyUrl = "../Plan/getDataList?dataType=pzyl&condition=";
    // var cData = new Array();
    
    /*
    *加载存货bom
    * */
    function loadBOM() {
        var conditon = JSON.stringify(FormToJson("qForm"));
        layui.use('table', function () {
            var table = layui.table;
            t_table = layui.table;
            var laydate = layui.laydate;
            var cols = table.render({
                elem: '#list'
                , url: dUrl + conditon
                , skin: 'row' //表格风格
                , even: true
                , page: true
                , limits: [50, 70, 100]
                , limit: 50 //每页默认显示的数量
                , cols: [[
                      // { type: 'checkbox', fixed: 'left' }
                     { field: 'proCode', align: 'center', title: '类别编码', width: 130 }
                    , { field: 'proName', align: 'center', title: '类别名称', width: 180 }
                    , { field: 'memo', align: 'center', title: '使用规格', width: 180 }
                    , { field: 'unitName', align: 'center', title: '计量单位', width: 90 }
                    , { field: 'bzValue', align: 'center', title: '标准用量', width: 120 }
                    , { field: 'inNum', align: 'center', title: '库存数', width: 120 }
                    , { field: 'useNum', align: 'center', title: '可用数量', width: 130 }
                    // , { field: 'memo', align: 'center', title: '采购数量', width: 130, edit: 'text' }
                    , { field: 'right', align: 'center', title: '', toolbar: '#barDemo', width: 100 }
                ]],done: function (res, curr, count) {
                    
                    currPage = curr;
                }
            });


            //监听工具条
            table.on('tool(list)', function (obj) {
                var data = obj.data;
                if (obj.event == 'view') {
                    var webUrl = "../Plan/PlanStockDetail?proCode=" + data.proCode + "&numType=" + data.numType + "&plCode=" + plCode + "&unitCode="+data.unitCode;
                    var title = data.proName + "-库存明细";
                    newOpen(webUrl, title);
                }
            });



        });
    }
    /**
     * 计划占用明细
     * **/
    function ZhYList() {
        layui.use('table', function () {
            var table = layui.table;
            t_table = layui.table;
            var laydate = layui.laydate;
            var cols = table.render({
                elem: '#zylist'
                , url: zyUrl + plCode
                , skin: 'row' //表格风格
                , even: true
                , page: true
                , limits: [15, 20, 30]
                , limit: 15 //每页默认显示的数量
                , cols: [[
                    { field: 'barCode', align: 'center', title: '条码编码', width: 130 }
                    , { field: 'proCode', align: 'center', title: '存货编码', width: 130 }
                    , { field: 'proName', align: 'center', title: '存货名称', width: 180 }
                    , { field: 'spec', align: 'center', title: '规格', width: 180 }
                    , { field: 'number', align: 'center', title: '占用数量', width: 90 }
                    , { field: 'userName', align: 'center', title: '占用人员', width: 120 }
                    , { field: 'gxName', align: 'center', title: '使用工序', width: 120 }
                    , { field: 'houseName', align: 'center', title: '仓库', width: 120 }
                    , { field: 'createtime', align: 'center', title: '时间', width: 170 }
                    , { field: 'right', align: 'center', title: '', toolbar: '#zyTools', width: 100 }
                ]], done: function (data) {
                    $.each(data['data'], function (i, j) {
                        if (j['barStatus'] == "need-in") {
                            TableRowColor('layui-table-main', i, '#F9FFB2');
                        }
                    });
                }
            });


            //监听工具条
            table.on('tool(zylist)', function (obj) {
                var data = obj.data;
                if (obj.event == 'del') {
                    layer.confirm('确定要取消占用？', function (index) {

                        $.ajax({
                            url: "../Plan/DelPlanZhanYong",
                            data: { "dataId": data.id },
                            type: "post",
                            success: function (data) {
                                if (data.result) {
                                    obj.del();
                                    loadBOM();
                                } else {
                                    layer.msg(data.message);
                                }
                            }
                        });

                        layer.close(index);
                    });
                }
            });


        });
    }
    
    

 

    function newOpen(webUrl,title) {
        layer.open({
            type: 2,
            maxmin: false,
            fix: false,
            title: title,
            area: ["98%", "98%"],
            closeBtn: 1,
            shadeClose: true,
            content: webUrl,
            //关闭弹出框的回调函数，不管弹出框是手动关闭还是通过脚本进行关闭，都执行
            end: function () {
                loadBOM();
                ZhYList();
            }
        });
    }



    //选择原材料
    function seleCtProduct() {
        var webUrl = "../Plan/MOccupyWithOutBar?proCode=" + proCode + "&plCode=" + plCode + "&planNum=" + planNum + "&plProName=" + proName + "&plSpec=" + spec + "&cuName=" + cuName+"&numType=erp";
        var title = "库存明细";
        newOpen(webUrl,title);
    }

    


</script>

